package com.distribute.config;

import com.distribute.api.DolphinSchedulerClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(DolphinSchedulerClient.class)
@EnableConfigurationProperties(DolphinschedulerConfig.class)
public class DolphinSchedulerAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public DolphinSchedulerClient dolphinSchedulerClient(DolphinschedulerConfig dolphinschedulerConfig) {
        Config config = new Config(
                dolphinschedulerConfig.getUrl(),
                dolphinschedulerConfig.getTimeout(),
                dolphinschedulerConfig.getRetryTimes(),
                dolphinschedulerConfig.getServiceName()
        );
        return DolphinSchedulerClient.getInstance(config);
    }
}
